package com.cyz.controller;

import com.cyz.dao.WorkScoreDao;
import com.cyz.entity.WorkScore;
import com.cyz.vo.ScoreDTO;
import com.cyz.vo.StudentWorkDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("homeWorkScore")
public class WorkScoreController {
    @Autowired
    WorkScoreDao workScoreDao;

    @RequestMapping("/list/{account}")
    public List<ScoreDTO> list(@PathVariable String account){
        List<ScoreDTO> scoreDTOS = workScoreDao.getInfo(account);
        return scoreDTOS;
    }

    @RequestMapping("queryCourse/{account}")
    public List<String> queryCourse(@PathVariable String account){
       List<String> result = workScoreDao.getCourseName(account);
       return result;
    }

    @RequestMapping("all/{account}")
    public List<StudentWorkDto> all(@PathVariable String account, String courseName){
        List<StudentWorkDto> result = workScoreDao.getCourseWork(account, courseName);
        return result;
    }

    @RequestMapping("answer")
    public String update(int account, String task){
        WorkScore workScore = workScoreDao.selectById(account);
        workScore.setAnswer(task);
        workScoreDao.updateById(workScore);
        return "回答成功";
    }
}
